﻿
<div class="ld-tabs">
    <ul>
        <li class="k-state-active">银行帐号列表</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <button class="k-button" onclick="CreateNewBank()"><span class="k-icon k-i-plus"></span><span>添加新帐号</span></button>
        </div>
        <div id="grid_banks" style="text-align: center"></div>
    </div>
</div>
<script class="init">
    LocatedMenu("系统管理", "常用帐号设置");
</script>
<script class="grid_banks_columns">
    var banksFields = [{
        title: "#",
        field: "ID",
        width: 50
    }, {
        title: "银行名称",
        field: "BankName",
        width: 200
    }, {
        title: "帐号",
        field: "CardNo",
        width: 200
    }, {
        title: "操作",
        template: "#=GetOperations(ID)#",
        attributes: { style: "text-align:left" }
    }];

    function GetOperations(id) {
        var html = "<button class='k-button' onclick=\"EditBank(" + id + ")\"><span class='k-icon k-i-pencil'></span><span>修改</span></button>";
        html += "<button class='k-button' onclick=\"DeleteBank(" + id + ")\"><span class='k-icon k-i-close'></span><span>删除</span></button>";
        return html;
    }

    function EditBank(id) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改银行帐号信息" });
            wndGeneralEdit.refresh({ url: "/Financial/Bank/Edit/" + id });
            wndGeneralEdit.open();
        }
    }

    function DeleteBank(id) {
        if (confirm("真的要删除这个帐号吗?")) {
            Whale.Remote.Operation({
                url: "/Financial/Bank/Delete",
                parameters: { bankID: id },
                success: function (result) {
                    if ($("#grid_banks").length > 0)
                        $("#grid_banks").data("kendoGrid").dataSource.read();
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                }
            });
        }
    }

</script>

<script class="grid_config">
    $(function () {
        $("#grid_banks").kendoGrid({
            columns: banksFields,
            dataSource: Whale.dataSource({
                url: "/Financial/Bank/Gets"
            }),
            pageable: false,
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });

    function CreateNewBank(){
        wndGeneralEdit.setOptions({ title: "添加新的银行帐号" });
        wndGeneralEdit.refresh({ url: "/Financial/Bank/Edit" });
        wndGeneralEdit.open();
    }

    function FilterCustomers() {
        $("#grid_banks").data("kendoGrid").dataSource.page(0);
        $("#grid_banks").data("kendoGrid").dataSource.read();
    }
</script>